<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Flot Examples: Graph Legend</title>
	<link href="../examples.css" rel="stylesheet" type="text/css">
	<script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
	<script language="javascript" type="text/javascript" src="../../lib/jquery.mousewheel.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
	<script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>

    <script type="text/javascript">

	$(function() {
        var plot;
		function drawArrow(ctx, x, y, radius){
			ctx.beginPath();
			ctx.moveTo(x + radius, y + radius);
			ctx.lineTo(x, y);
			ctx.lineTo(x - radius, y + radius);
			ctx.stroke();
		}

		function drawSemiCircle(ctx, x, y, radius){
			ctx.beginPath();
			ctx.arc(x, y, radius, 0, Math.PI, false);
			ctx.moveTo(x - radius, y);
			ctx.lineTo(x + radius, y);
			ctx.stroke();
		}

        var data1 = [];
		for (var i = 0; i < 3; i += 0.005) {
			data1.push([i, 1.2 + Math.sin(i*10)]);
        }

		var data2 = [
            [0,0],
            [1,1],
            [2,2],
            [3,3]
		];

		var data2_points = {
			show: true,
			radius: 5,
			fillColor: "dodgerblue",
            symbol: "diamond",
		};

		var data3 = [
			[.7,3,.2,.4],
			[1.5,2.2,.3,.4],
			[2.3,1,.5,.2]
		];

		var data3_points = {
            show: true,
			radius: 5,
		};

		var data4 = [
			[1,2],
			[2,0.5],
			[2.7,2]
		];

		var data4_points = {
            //do not show points
            show: false,
            radius: 5,
            fillColor: "white",
		};

		var data5 = [
			[1.3, 1],
			[1.75, 2.5],
			[2.5, 0.5]
		];

		var data = [
            // area
            {color: "cyan", lines: {show: true, fill: true}, data: data1, label: "Area"},
            // bars
			{color: "orange", bars: {show: true, align: "center", barWidth: 0.25}, data: data5, label: "Bars"},
            //lines
            {color: "forestgreen", lines: {show: true, lineWidth: 4}, points: data4_points, data: data4, label: "Lines"},
            // points
            {color: "indigo", points: data2_points, data: data2, label: "Points"},
            // lines + points
			{color: "red",  lines: {show: true, lineWidth:2}, points: data3_points, data: data3, label: "Lines & Points"},
        ];

        var legendContainer = document.getElementById("legendContainer");
        var legendSettings = {
				position: "nw",
                show: true,
                noColumns: 2,
                container: legendContainer
            };
        $('#myForm input').on('change', function() {
            var val = $('input[name="myRadio"]:checked', '#myForm').val();

            $(legendContainer).html('');
            switch (val) {
                case 'se':
                    legendSettings.position = "se"
                    legendSettings.container = null;
                    break;
                case 'sw':
                    legendSettings.position = "sw"
                    legendSettings.container = null;
                    break;
                case 'ne':
                    legendSettings.position = "ne"
                    legendSettings.container = null;
                    break;
                case 'nw':
                    legendSettings.position = "nw"
                    legendSettings.container = null;
                    break;
                case 'container':
                    legendSettings.container = legendContainer;
                    break;
            }
            setupGraph();
        });

        setupGraph();
        drawGraph();

        function setupGraph() {
           plot = $.plot($("#placeholder"), data , {
                legend: legendSettings,
                series: {
                    lines: {
                        show: false
                    }
                },
                xaxis: {
                    autoScale: "none",
                    min: 0,
                    max: 3
                },
                yaxis: {
                    autoScale: "none",
                    min: 0,
                    max: 3.5
                },
                zoom: {
                    interactive: true
                },
                pan: {
                    interactive: true
                }
            });
        }

        function drawGraph() {
            plot.setData(data);
            plot.setupGrid();
            plot.draw();
            requestAnimationFrame(drawGraph);
        }

		// Add the Flot version string to the footer

		$("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
	});

	</script>
</head>
<body>

	<div id="header">
		<h2>Graph Legend</h2>
	</div>

	<div id="content">

		<div class="demo-container">
			<div id="placeholder" class="demo-placeholder"></div>
        </div>
        <p>Legend Container:</p>
        <div id="legendContainer" class="legend" style="width:9em;height:8em;border-style:solid;border-color:threedface"></div>

        <div>
            <fieldset id="myForm">
                <legend>Legend Position</legend>
                <input type="radio" name="myRadio" value="se"> SE - Over Graph <br>
                <input type="radio" name="myRadio" value="sw"> SW - Over Graph <br>
                <input type="radio" name="myRadio" value="ne"> NE - Over Graph <br>
                <input type="radio" name="myRadio" value="nw"> NW - Over Graph <br>
                <input type="radio" name="myRadio" value="container" checked="checked"> Container <br>
            </fieldset>
        </div>
	</div>

	<div id="footer">
		Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
	</div>

</body>
</html>
